﻿using System.Text.RegularExpressions;

namespace MiniUtils;

public class FileUtils
{
    /// <summary>
    /// 查询文件夹下，所有符合的文件路径
    /// </summary>
    /// <param name="folderPath">文件夹路径</param>
    /// <param name="regexStr">正则匹配文件名</param>
    /// <returns></returns>
    public static string[] GetFilePath(string folderPath, string regexStr)
    {
        List<string> filePaths = new(Directory.GetFiles(folderPath));
        Regex regex = new(regexStr);
        for (int i = filePaths.Count - 1; i >= 0; i--)
        {
            if (!regex.IsMatch(Path.GetFileName(filePaths[i])))
            {
                filePaths.RemoveAt(i);
            }
        }
        return filePaths.ToArray();
    }
}
